<?php
include '/StatsProtocol.php'
include '/HtmlString.php'

    class KarieraReader implements IReader 
    {
        private $i = 0;

        public function getLinks()
        {
            $statsProtocol = new StatsProtocol();
            $htmlString = new HtmlString();

            $a = 1;
            $advs = array();
            $continueSearch = true;

            while ($continueSearch)
            {
                $this->i++;
                for ($k = 1; $k < 26; $k++)
                {
                    $htmlCode = $statsProtocol->getHtmlCode("http://www.kariera.gr/GR/JobSeeker/Jobs/JobResults.aspx?IPath=JRTCM&excrit=QID%3dA3853799130912%3bst%3dA%3buse%3dALL%3bCID%3dGR%3bSID%3d%3f%3bTID%3d0%3bENR%3dNO%3bDTP%3dDRNS%3bYDI%3dYES%3bIND%3dALL%3bPDQ%3dAll%3bJN%3dJN008%3bPAYL%3d0%3bPAYH%3dGT120%3bPOY%3dNO%3bETD%3dALL%3bRE%3dALL%3bMGT%3dDC%3bSUP%3dDC%3bFRE%3d30%3bCHL%3dIL%3bQS%3dSID_UNKNOWN%3bSS%3dNO%3bTITL%3d0%3bOB%3d-modifiedint%3bRAD%3d30%3bJQT%3dRAD%3bJDV%3dFalse%3bExpHigh%3dGT50%3bExpLow%3d0%3bMaxLowExp%3d-1&pg=" . $i . "&sc_cmp2=JS_GR_JRP_Jumpto_1");
                    $searchString = "J_D__ctl" . $k . "_cblTitle";

                    $FirstChr = strpos($htmlCode,$SearchString);
                    if ($FirstChr == -1)
                    {
                        break;
                    }
                    $cuttedHtmlCode = substr($htmlCode,$FirstChr);
                    $cleanedHtml = $htmlString->cleanUrl($cuttedHtmlCode, "http", "\"" . ">", "kar");
                    $advs[]=$cleanedHtml;
                }
                $a++;
                $htmlCode = $statsProtocol->getHtmlCode("http://www.kariera.gr/GR/JobSeeker/Jobs/JobResults.aspx?IPath=JRTCM&excrit=QID%3dA3853799130912%3bst%3dA%3buse%3dALL%3bCID%3dGR%3bSID%3d%3f%3bTID%3d0%3bENR%3dNO%3bDTP%3dDRNS%3bYDI%3dYES%3bIND%3dALL%3bPDQ%3dAll%3bJN%3dJN008%3bPAYL%3d0%3bPAYH%3dGT120%3bPOY%3dNO%3bETD%3dALL%3bRE%3dALL%3bMGT%3dDC%3bSUP%3dDC%3bFRE%3d30%3bCHL%3dIL%3bQS%3dSID_UNKNOWN%3bSS%3dNO%3bTITL%3d0%3bOB%3d-modifiedint%3bRAD%3d30%3bJQT%3dRAD%3bJDV%3dFalse%3bExpHigh%3dGT50%3bExpLow%3d0%3bMaxLowExp%3d-1&pg=" . $a . "&sc_cmp2=JS_GR_JRP_Jumpto_1");
                $continueSearch = $htmlString->pageExists($htmlCode, "Συγγνώμη, δε βρέθηκαν αποτελέσματα που να ταιριάζουν με τα κριτήρια που θέσατε.");
            }
            return $advs;
        }

        public function doTheWork()
        {
            $statsProtocol = new StatsProtocol();
            $htmlString = new HtmlString();
            $advs = array();
            $advsResult = array();
            $reader = new KarieraReader();
            $advs = $reader->getLinks();

            for ($j = 0; $j < count($advs); $j++) 
            {
                $advertisements = new Advertisements();
                $htmlCode = $statsProtocol->getHtmlCode($advs['$j']);
                $cleanedhtmlCode = $htmlString->cleanUrl($htmlCode, "<!-- Description Content -->", "<!-- End Description Content -->", "kar");
                $cleanedhtmlCode = $htmlString->StripTagsCharArray($cleanedhtmlCode);
                $advertisements->setContent($cleanedhtmlCode);
                $date = $htmlString->getDate(htmlCode, "Τελευταία ανανέωση:", "kar");
                $advertisements->setDate($date);
                $advsResult[]=$advertisements;
            }
            return $advsResult;
        }
    }
?>
